/**
 * 
 */
package com.cqan.core.dao.impl;


import java.io.Serializable;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.cqan.core.dao.IBaseDao;
import com.cqan.core.exception.BasicException;
import com.cqan.core.pojo.DomainObject;

/**
 * @author wuhui
 *
 * 下午03:53:56
 */
public abstract class BaseDaoImpl extends SqlMapClientDaoSupport implements IBaseDao {

	public abstract String getNameSpace();

    public <T extends DomainObject> T save(DomainObject obj)
        throws BasicException {
        try {
            getSqlMapClientTemplate().insert(getNameSpace()+".save", obj);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BasicException(e);
        }
       
        return (T)obj;
    }

    public void update(DomainObject obj) throws BasicException {
        getSqlMapClientTemplate().update(getNameSpace()+".update", obj);
    }

    public void delete(DomainObject obj) throws BasicException {
        getSqlMapClientTemplate().delete(getNameSpace()+".delete", obj);

    }

    public <T extends DomainObject> T loadByUid(Serializable uid)
        throws BasicException {
        return (T) getSqlMapClientTemplate().queryForObject(getNameSpace()+".loadByUid", uid);
    }

}
